﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TSL_Tools.XMLTools;
using System.Xml;

namespace ReportingAppConfig
{
    public class ChartFormatPropertySets
    {
        #region -- Public Properties ----------------------------------------------------
        public Dictionary<string, SetProperties> ChartFormatSets { get; private set; }
        #endregion

        #region -- Private Properties ---------------------------------------------------
        #endregion

        #region -- Constructors ---------------------------------------------------------
        public ChartFormatPropertySets() 
        {
            ChartFormatSets = new Dictionary<string, SetProperties>();
        }
        #endregion

        #region -- Public Methods -------------------------------------------------------
        /// <summary>
        /// Used to load the config user settings into the  <see cref="AppConfiguration"/> class settings
        /// </summary>
        public void GetConfigValues(XmlDocument xDoc)
        {
            XmlNode xNode = xDoc.SelectSingleNode("Configuration/ChartFormatPropertySets");
            {
                foreach (XmlNode xChild in xNode.SelectNodes("ChartFormatPropertySet"))
                {
                    SetProperties properties = new SetProperties();
                    string sName = XmlHelper.GetXmlAttributeValue(xChild, "name", "");
                    foreach (XmlNode xSubChild in xChild.SelectNodes("*[.]"))
                    {
                        properties.Add(xSubChild.Name, xSubChild.InnerText);
                    }
                    ChartFormatSets.Add(sName, properties);
                }
            }
        }

        /// <summary>
        /// Used to set the <see cref="AppConfiguration"/> class settings back into the config user settings file and then to save them.
        /// </summary>
        public void SaveConfigValues(XmlDocument xDoc)
        {
        }

        #endregion

        #region -- Private Methods ------------------------------------------------------
        #endregion
    }

    public class SetProperties
    {
        public Dictionary<string, string> PropertyList { get; set; }

        public SetProperties()
        {
            PropertyList = new Dictionary<string, string>();
        }

        public bool Add(string Key, string Value)
        {
            if (PropertyList.ContainsKey(Key))
                return false;
            else
            {
                PropertyList.Add(Key, Value);
                return true;
            }
        }
    }
}
